package ;

import browser.display.Shape;
import nme.text.TextField;
import haxe.Json;
import nme.Assets;
import nme.display.Bitmap;
import nme.display.DisplayObject;
import nme.display.Sprite;
import nme.events.Event;
import nme.Lib;
import org.zdc.damasteel.Application;
import org.zdc.damasteel.Button;
import org.zdc.damasteel.Component;
import org.zdc.damasteel.skin.ButtonSkin;
import org.zdc.damasteel.skin.ComponentSkin;
import org.zdc.utils.Helper;
import org.zdc.utils.UIHelper;
using Lambda;

/**
 * ...
 * @author simple slime
 */

class Main extends Sprite 
{
	public static var t:TextField = new TextField();
	
	public function new() 
	{
		super();
		#if iphone
		Lib.current.stage.addEventListener(Event.RESIZE, init);
		#else
		addEventListener(Event.ADDED_TO_STAGE, init);
		#end
	}

	private function init(e) 
	{
		// entry point
		
		// new to Haxe NME? please read *carefully* the readme.txt file!
	}
	
	static public function main() 
	{
		var stage = Lib.current.stage;
		stage.scaleMode = nme.display.StageScaleMode.NO_SCALE;
		stage.align = nme.display.StageAlign.TOP_LEFT;
		
		Lib.current.addChild(new Main());
		
		//var a:Component = new Component();
		//trace(Helper.getInheritClasses(Component, Sprite));   
		//trace(Helper.classIs(Sprite, DisplayObject));
		//trace(Type.getSuperClass(Component) == Sprite);
		
		//var a:ButtonSkin;
		
		Application.bootStrap(); 
		var b = new Button();
		Lib.current.addChild(b);
		
		//var h1:Dynamic = { x: 1, y:2 };
		//var h2:Dynamic = { z : 3, x: 2 };
		//trace(Json.stringify(Helper.joinObjects(h1, h2, false)));
		
		var bmp = new Bitmap();
		Lib.current.addChild(bmp);
		var d = Assets.getBitmapData("img/a.jpg");
		bmp.bitmapData = d;
		
		Lib.current.addChild(t);
		t.width = 1000;
		t.height = 500;
		t.y = 300;
		
		//say(Json.stringify( { x: "HHHL" } ));
		//var h:Hash<Dynamic> = new Hash<Dynamic>();
		//h.set("x", "hhh");
		//say(Json.stringify(h));
		
		//var bb = new B();
		//bb.hello();
		
		var bgDio:Shape = null;
		if (bgDio == null) {
			bgDio = new Shape();
			//Lib.current.addChild(bgDio);
			bgDio.y = 400;
			bgDio.x = 100;
			bgDio.width = 100;
			bgDio.height = 300;
		}
		UIHelper.bottom(bgDio);
		var g = bgDio.graphics;
		var c:Int = 0;
		var alpha:Float = 1;
		g.beginFill(c, 1);
		g.drawRect(0, 0, 200, 300);		
		g.endFill();
		Lib.current.addChild(bgDio);
	}
	
	public static function say(msg:Dynamic):Void {
		t.appendText(msg + "\n");
	}
	
}
